import { createRouter, createWebHashHistory } from 'vue-router'
import HomePage from '../views/HomePage.vue'
import ParameterConfig from '../views/ParameterConfig.vue'
import CustomCodeGeneration from '../views/CustomCodeGeneration.vue'
import LogViewer from '../views/LogViewer.vue'
import CodeGenerationManagement from '../views/CodeGenerationManagement.vue'
import DataDictionary from '../views/DataDictionary.vue'
import RequirementAnalysis from '../views/RequirementAnalysis.vue'
import CodeStepGenerator from '../views/CodeStepGenerator.vue'

// 获取URL参数判断是否为管理员
const urlParams = new URLSearchParams(window.location.search)
const isAdmin = urlParams.has('admin') && urlParams.get('admin') === '1'

const routes = [
  {
    path: '/',
    name: 'Home',
    component: HomePage
  },
  {
    path: '/parameter',
    name: 'ParameterConfig',
    component: ParameterConfig
  },
  {
    path: '/custom-code-generation',
    name: 'CustomCodeGeneration',
    component: CustomCodeGeneration
  },
  {
    path: '/code-generation-management',
    name: 'CodeGenerationManagement',
    component: CodeGenerationManagement
  },
  {
    path: '/data-dictionary',
    name: 'DataDictionary',
    component: DataDictionary
  },
  {
    path: '/requirement-analysis',
    name: 'RequirementAnalysis',
    component: RequirementAnalysis
  },
  {
    path: '/code-step-generator',
    name: 'CodeStepGenerator',
    component: CodeStepGenerator
  },
  ...(isAdmin ? [{
    path: '/log-viewer',
    name: 'LogViewer',
    component: LogViewer
  }] : []),
  {
    path: '/:pathMatch(.*)*',
    redirect: '/'
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

export default router
